package com.zxl.live.tools.alert;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.provider.Settings;

import java.util.List;

/**
 * 功能：
 * 作者： caijun
 * 时间： 2017/5/10  14 : 24
 */
public class MGotoAlertSet implements AlertPermissionUtils.GotoAlertManager {
    private static final String SCHEME = "package";

    public boolean canAction(Context context) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, 0);
        if (null != list && list.size() > 0) {
            return true;
        }
        return false;
    }

    @Override
    public void gotoAlert(Context context) {
        try {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName()));
            context.startActivity(intent);
        } catch (Exception e) {
            try {
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.fromParts(SCHEME, context.getPackageName(), null));
                context.startActivity(intent);
            } catch (Exception e1) {

            }
        }
    }
}
